// shop page
// ============

define(['zepto', 'utils', 'JST', 'chart'], 
function($, utils, JST) {
  return {
    init: function(data) {
      this.initPage(data)
    },
    
    initPage: function(data) {
      
      var month = [],
          weight = [],
          bmi = [],
          sm = [],
          bf = [],
          bfr = [],
          whr = [],
          bm = [];
      
      for(var i in data) {
        month.push(data[i].recordMonthDay);
        weight.push(parseFloat(data[i].weight).toFixed(1));
        bmi.push(parseFloat(data[i].bmi).toFixed(1));
        sm.push(parseFloat(data[i].sm).toFixed(1));
        bf.push(parseFloat(data[i].bf).toFixed(1));
        bfr.push(parseFloat(data[i].bfr).toFixed(1));
        whr.push(parseFloat(data[i].whr).toFixed(1));
        bm.push(parseFloat(data[i].bm).toFixed(1));
      }
      
      var initChartData = {
        labels : month,
        datasets : [
          {
            label: "体重",
            fillColor : "rgba(0,0,0,0)",
            strokeColor : "rgba(253,222,0,1)",
            pointColor : "rgba(253,222,0,1)",
            pointStrokeColor : "#ffde00",
            pointHighlightFill : "#ffde00",
            data : null
          }
          
        ]
  
      }
      
      var ctx = document.getElementById("bmi_canvas").getContext("2d");
      initChartData.datasets[0].data = bmi;
      window.myLine = new Chart(ctx).Line(initChartData, {
        scaleShowGridLines : false,
        animation : true,
        responsive: true
      });
      
      var ctx = document.getElementById("sm_canvas").getContext("2d");
      initChartData.datasets[0].data = sm;
      window.myLine = new Chart(ctx).Line(initChartData, {
        scaleShowGridLines : false,
        animation : true,
        responsive: true
      });
      
      var ctx = document.getElementById("bf_canvas").getContext("2d");
      initChartData.datasets[0].data = bf;
      window.myLine = new Chart(ctx).Line(initChartData, {
        scaleShowGridLines : false,
        animation : true,
        responsive: true
      });
      
      var ctx = document.getElementById("bfr_canvas").getContext("2d");
      initChartData.datasets[0].data = bfr;
      window.myLine = new Chart(ctx).Line(initChartData, {
        scaleShowGridLines : false,
        animation : true,
        responsive: true
      });
      
      var ctx = document.getElementById("whr_canvas").getContext("2d");
      initChartData.datasets[0].data = whr;
      window.myLine = new Chart(ctx).Line(initChartData, {
        scaleShowGridLines : false,
        animation : true,
        responsive: true
      });
      
      var ctx = document.getElementById("bm_canvas").getContext("2d");
      initChartData.datasets[0].data = bm;
      window.myLine = new Chart(ctx).Line(initChartData, {
        scaleShowGridLines : false,
        animation : true,
        responsive: true
      });
      
      var ctx = document.getElementById("weight_canvas").getContext("2d");
      initChartData.datasets[0].data = weight;
      window.myLine = new Chart(ctx).Line(initChartData, {
        scaleShowGridLines : false,
        animation : true,
        responsive: true
      });
    }
  }
})